<template>
  <div class="app-container">
    <basic-container v-show="showSearch">
      <common-search @handleQuery="handleQuery" @resetQuery="resetQuery">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="78px" size="small">
          <el-form-item label="监管场所" prop="areaNo">
            <el-input
              v-model="queryParams.areaName"
              placeholder="请输入监管场所"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="通道" prop="channelNo">
            <el-input
              v-model="queryParams.channelName"
              placeholder="请输入通道"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="进出类型" prop="ieType">
            <el-select v-model="queryParams.ieType" placeholder="请选择进出类型" clearable>
              <el-option
                v-for="dict in dict.type.sys_i_e_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="IC卡号" prop="icNo">
            <el-input
              v-model="queryParams.icNo"
              placeholder="请输入ic卡号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="车牌号码" prop="veNo">
            <el-input
              v-model="queryParams.veNo"
              placeholder="请输入车牌号码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="批次号" prop="manifestId">
            <el-input
              v-model="queryParams.manifestId"
              placeholder="请输入运输批次号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="业务类型" prop="businessId">
            <el-input
              v-model="queryParams.businessId"
              placeholder="请输入业务类型"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="单证代码" prop="billCode">
            <el-input
              v-model="queryParams.billCode"
              placeholder="请输入单证代码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="货物名称" prop="goodsName">
            <el-input
              v-model="queryParams.goodsName"
              placeholder="请输入货物名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="海关编码" prop="customsCode">
            <el-input
              v-model="queryParams.customsCode"
              placeholder="请输入海关编码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="放行时间" prop="checkTime">
            <el-date-picker clearable
                            v-model="checkTime"
                            type="daterange"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :default-time="['00:00:00','23:59:59']"
                            @keyup.enter.native="handleQuery"
            >
            </el-date-picker>
          </el-form-item>

        </el-form>
      </common-search>
    </basic-container>
    
    <basic-container>
      <el-row :gutter="10" class="mb8 el-row">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="hdGatherList" @row-dblclick="showDetail" stripe border size="small">
        <el-empty slot="empty" :image="require('@/assets/images/empty.png')" :image-size="260"></el-empty>
        <el-table-column label="车牌号码" align="center" min-width="100" prop="veNo"/>
        <el-table-column label="IC卡号" align="center" min-width="100" show-overflow-tooltip prop="icNo"/>
        <el-table-column label="地磅重量" align="center" prop="crossWeight"/>
        <el-table-column label="场所代码" align="center" min-width="150" show-overflow-tooltip prop="areaNo">
          <template slot-scope="scope">
            {{ scope.row.areaName }} [{{ scope.row.areaNo }}]
          </template>
        </el-table-column>
        <el-table-column label="通道代码" align="center" min-width="150" show-overflow-tooltip prop="channelNo">
          <template slot-scope="scope">
            {{ scope.row.channelName }} [{{ scope.row.channelNo }}]
          </template>
        </el-table-column>
        <el-table-column label="进出场" align="center" prop="ieType">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_i_e_type" :value="scope.row.ieType"/>
          </template>
        </el-table-column>
        <el-table-column label="采集时间" align="center" prop="gatherTime" width="180">
        </el-table-column>
        <el-table-column label="验放结果" align="center" min-width="150" show-overflow-tooltip prop="checkResult">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.sys_release_result" :value="scope.row.checkResult"/>
          </template>
        </el-table-column>
        <el-table-column label="验放提示" prop="checkHint" min-width="150" show-overflow-tooltip/>
        <el-table-column label="LED提示" prop="ledHint" min-width="150" show-overflow-tooltip/>
        <el-table-column label="批次号" prop="manifestId" min-width="150" show-overflow-tooltip/>
        <el-table-column label="业务名称" align="center" prop="businessName" min-width="150" show-overflow-tooltip/>
        <el-table-column label="货物重量" align="center" prop="goodsWts"/>
        <el-table-column label="单证代码" prop="billCode" min-width="150" show-overflow-tooltip/>
        <el-table-column label="空车重" align="center" prop="veWt"/>
        <el-table-column label="放行时间" align="center" prop="checkTime" width="180">
        </el-table-column>
        <el-table-column label="车辆代码" align="center" prop="transportId" min-width="100" show-overflow-tooltip/>
        <el-table-column label="操作" align="center" fixed="right" width="80px" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="showDetail(scope.row)"
              v-hasPermi="['kmwlpts:gather:list']"
            >详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </basic-container>
    
    <!-- 添加或修改放行记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="isViewDisabled">
        <el-row>
          <el-col :span="12">
            <el-form-item label="采集序号" prop="seqNo" label-width="100px">
              <el-input v-model="form.seqNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场所代码" prop="areaNo" label-width="100px">
              <el-input v-model="form.areaNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="场所名称" prop="areaName" label-width="100px">
              <el-input v-model="form.areaName" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通道代码" prop="channelNo" label-width="100px">
              <el-input v-model="form.channelNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通道名称" prop="channelName" label-width="100px">
              <el-input v-model="form.channelName" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="进出类型" prop="ieType" label-width="100px">
              <el-select v-model="form.ieType" placeholder="">
                <el-option
                  v-for="dict in dict.type.sys_i_e_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="IC卡号" prop="icNo" label-width="100px">
              <el-input v-model="form.icNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车牌号码" prop="veNo" label-width="100px">
              <el-input v-model="form.veNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地磅重量" prop="crossWeight" label-width="100px">
              <el-input v-model="form.crossWeight" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="验放结果" prop="checkResult" label-width="100px">
              <el-select v-model="form.checkResult" placeholder="">
                <el-option
                  v-for="dict in dict.type.sys_release_result"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运输批次号" prop="manifestId" label-width="100px">
              <el-input v-model="form.manifestId" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运输批次号" prop="businessId" label-width="100px">
              <el-input v-model="form.businessId" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运输批次号" prop="businessName" label-width="100px">
              <el-input v-model="form.businessName" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="货物名称" prop="goodsName" label-width="100px">
              <el-input v-model="form.goodsName" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="装载货物重量" prop="goodsWts" label-width="100px">
              <el-input v-model="form.goodsWts" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单证代码" prop="billCode" label-width="100px">
              <el-input v-model="form.billCode" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="空车重" prop="veWt" label-width="100px">
              <el-input v-model="form.veWt" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采集方式" prop="gatherModel" label-width="100px">
              <el-input v-model="form.gatherModel" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注说明" prop="rmk" label-width="100px">
              <el-input v-model="form.rmk" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理放行时间" prop="useTime" label-width="100px">
              <el-input v-model="form.useTime" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="验放类型" prop="checkBody" label-width="100px">
              <el-input v-model="form.checkBody" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆海关编码" prop="transportId" label-width="100px">
              <el-input v-model="form.transportId" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关区代码" prop="customsCode" label-width="100px">
              <el-input v-model="form.customsCode" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="转关单号" prop="customsTransferNo" label-width="100px">
              <el-input v-model="form.customsTransferNo" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="错误提示编码" prop="errorCode" label-width="100px">
              <el-input v-model="form.errorCode" placeholder=""/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="挂车重量" prop="veTrayWt" label-width="100px">
              <el-input v-model="form.veTrayWt" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="集装箱重量" prop="containerWt" label-width="100px">
              <el-input v-model="form.containerWt" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="刷卡时间" prop="gatherTime" label-width="100px">
              <el-date-picker clearable size="small"
                              v-model="form.gatherTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="同步时间" prop="syncDate" label-width="100px">
              <el-date-picker clearable size="small"
                              v-model="form.syncDate"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="处理放行时间" prop="checkTime" label-width="100px">
              <el-date-picker clearable size="small"
                              v-model="form.checkTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="验放提示" prop="checkHint" label-width="100px">
              <el-input v-model="form.checkHint" type="textarea" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="提运单号" prop="billNo" label-width="100px">
              <el-input v-model="form.billNo" type="textarea" placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报关单号" prop="entryId" label-width="100px">
              <el-input v-model="form.entryId" type="textarea" placeholder=""/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="金二放行结果" prop="checkAiHint" label-width="100px">
              <el-input v-model="form.checkAiHint" type="textarea" placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!isViewDisabled">确 定</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>

import {getGatherById, listGather, listGatherByIds} from "@/api/kmwlpts/gkHdGather";

export default {
  name: "Err_GkHdGather",
  dicts: ['sys_i_e_type', 'sys_release_result'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      //显示检查项目列表
      checkItemTableVisible: false,
      //详情显示的时候，表单编辑禁用
      isViewDisabled: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 放行记录表格数据
      hdGatherList: [],
      // 弹出层标题
      title: "",
      //
      checked: true,
      //
      checkTime: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaName: null,
        channelName: null,
        ieType: null,
        icNo: null,
        veNo: null,
        checkResult: 'N',
        manifestId: null,
        businessId: null,
        entryId: null,
        goodsName: null,
        billCode: null,
        customsCode: null,
        from: null,
        to: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  directives: {
    print
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询放行记录列表 */
    getList() {
      this.loading = true;
      let code = this.$route.query.code;
      if (code !== 'undefined' && code !== "") {
        this.queryParams.billCode = code;
      }
      listGather(this.queryParams).then(response => {
        this.hdGatherList = response.rows;
        this.total = response.total;
        this.loading = false;
        code = "";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHdGather(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHdGather(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.checkResult = 'N';
      if (this.checkTime != null) {
        this.queryParams.from = this.checkTime[0];
        this.queryParams.to = this.checkTime[1]
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.checkTime = [];
      this.handleQuery();

    },

    //显示详情
    showDetail(row) {
      this.reset();
      //关闭表单编辑模式
      this.isViewDisabled = true;
      const id = row.id;
      getGatherById(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "详情";
      });
    },
// 表单重置
    reset() {
      this.form = {
        id: null,
        seqNo: null,
        areaNo: null,
        areaName: null,
        channelNo: null,
        channelName: null,
        ieType: null,
        gatherTime: null,
        icNo: null,
        veNo: null,
        crossWeight: null,
        checkResult: null,
        checkHint: null,
        billNo: null,
        manifestId: null,
        businessId: null,
        businessName: null,
        entryId: null,
        goodsWts: null,
        goodsName: null,
        billCode: null,
        veEmpty: null,
        veWt: null,
        gatherModel: null,
        rmk: null,
        syncDate: null,
        checkTime: null,
        useTime: null,
        checkAiHint: null,
        checkAiResult: null,
        checkBody: null,
        transportId: null,
        customsCode: null,
        customsTransferNo: null,
        errorCode: null,
        veTrayWt: null,
        containerWt: null
      };
      this.resetForm("form");
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有放行记录数据项？').then(() => {
        this.exportLoading = true;
        return exportHdGather(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }

};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266;
}

.el-select.el-input.is-disabled ::v-deep .el-input__inner {
  color: #606266 !important;
}

.el-textarea.is-disabled ::v-deep .el-textarea__inner {
  color: #606266;
}

::v-deep .bor_1 {
  border: 1px black solid;
}

::v-deep input[disabled], input:disabled, input.disabled {
  -webkit-text-fill-color: #606266;
  background: #F5F7FA;
  -webkit-opacity: 1;
  opacity: 1;
  cursor: not-allowed;
}

::v-deep .el-select {
  width: 270px;
}

::v-deep .el-textarea__inner {
  width: 270px;
}

::v-deep .el-input__inner {
  width: 270px;
}

::v-deep .el-date-editor--date {
  width: 270px;
}

</style>
